//
//  rootView.m
//  qulvyou
//
//  Created by mmyy on 15/10/27.
//  Copyright (c) 2015年 mmyy. All rights reserved.
//

#import "rootView.h"

@interface rootView ()

@end

@implementation rootView

- (void)viewDidLoad {
    [super viewDidLoad];
    NSInteger timer = [[NSUserDefaults standardUserDefaults] integerForKey:@"timer"];
    if (timer == 0) {
        [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"timer"];
        [self createNavcation];
    }else {
        [self start];
    }
    // Do any additional setup after loading the view.
}

-(void)start
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ISFirst" object:nil userInfo:nil];
}
-(void)createNavcation
{
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view addSubview:scrollView];
    scrollView.pagingEnabled = YES;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    NSArray *imageArray = @[@"first", @"second", @"thread"];
    for (int i = 0; i < imageArray.count; i++)
    {
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(i * self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
        imageV.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png", imageArray[i]]];
        [scrollView addSubview:imageV];
        if (i == 2) {
            imageV.userInteractionEnabled = YES;
            UIButton *startBt = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 180, self.view.frame.size.height - 120, 150, 40)];
            [startBt setTitle:@"开启旅程" forState:UIControlStateNormal];
            [startBt setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
            startBt.layer.cornerRadius = 5;
            startBt.layer.masksToBounds = YES;
            startBt.layer.borderColor = [UIColor greenColor].CGColor;
            startBt.layer.borderWidth = 2;
            [imageV addSubview:startBt];
            [startBt addTarget:self action:@selector(btClick:) forControlEvents:UIControlEventTouchUpInside];
        }

//        imageV.image = image;
        
    }
    scrollView.contentSize = CGSizeMake(imageArray.count * self.view.frame.size.width, 0);
    
    
}
-(void)btClick:(UIButton *)sender
{
    if ([sender.currentTitle isEqualToString:@"开启旅程"]) {
        [self start];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
